// pages/study/study.js
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        sheetShow: false,
        actions: [
            {
                name: '拍摄',
                subname: '照片或视频'
            },
            {
                name: '从相册选择',
            }
        ],
        columns: [
            {text:'软件工程', disabled: true}, 
            {text:'环艺专业'}, 
            {text:'会计专业'}, 
            {text:'土木专业'}, 
            {text:'交互专业'}
        ],
        date: '',
        show: false,
        minDate: "",
        maxDate: "",
        formatter(day) {
            const month = day.date.getMonth() + 1;
            const date = day.date.getDate();
            if (month === 5) {
              if (date === 2) {
                day.bottomInfo = '余号:5';
              } else if (date === 6) {
                day.bottomInfo = '余号:5';
              } else{
                day.bottomInfo = '余号:99';
              }
            }
            return day;
        },
    },
    //点击手机自爆按钮
    phoneBomm(){
        Dialog.confirm({
            title: '系统提示',
            message: '是否确定手机在5秒后自爆？',
        })
        .then(() => {//确定
            var i = 6;
            var it = setInterval(() => {
                i--;

                Toast('倒计时：'+i);

                if(i == 0){
                    Toast('BOOM!!!!!');
                }
                if(i == 0){
                    clearInterval(it);
                }
            },1000);
        })
        .catch(() => {
            // on cancel
        });
    },
    //打开
    onOpenSheet() {
        console.log(1);
        this.setData({ sheetShow: true });
    },
    //关闭
    onCloseSheet() {
        this.setData({ sheetShow: false });
    },
    //选择结果
    onSelectSheet(event) {
        console.log(event.detail);
    },
    onChange(event) {
        const { picker, value, index } = event.detail;
        //Toast(`当前值：${value}, 当前索引：${index}`);
    },
    onDisplay() {
        // 注释：Date.parse() // 转化时间戳
        // 时间
        var now = new Date(); // 当前日期
        var nowDayOfWeek = now.getDay(); // 今天本周的第几天
        var nowDay = now.getDate();    // 当前日期
        var nowMonth = now.getMonth(); // 当前月
        var nowYear = now.getYear();   // 当前年
        nowYear += (nowYear < 2000) ? 1900 : 0; 
        //下周一
        var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 8); 
        //下周日
        var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek) + 8);
        this.setData({
            minDate:weekStartDate.getTime(),
            maxDate:weekEndDate.getTime()
        })

        this.setData({ show: true });
    },
    onClose() {
        this.setData({ show: false });
      },
    formatDate(date) {
        date = new Date(date);
        //标准的年月日格式
        return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
       // return `${date.getMonth() + 1}/${date.getDate()}`;

    },
    onConfirm(event) {
        this.setData({
          show: false,
          date: this.formatDate(event.detail),
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})